#ifndef GAMEELEMENTFACTORY_H
#define GAMEELEMENTFACTORY_H

#include <map>
#include <algorithm>
#include "GameElement.h"
#include "ElementDoor.h"
#include "ElementSwitch.h"
#include "ElementSpikes.h"
#include "ElementLadder.h"
#include "ElementEnemy.h"

#define MAX_ELEMENTS 256


struct vectorComp{
    bool operator()(const vector3<int>& a, const vector3<int>& b) const{
        return (a.x<b.x || a.y<b.y || a.z<b.z);
    }
};

typedef map< vector3<int>, GameElement*> MAP_TYPE;

class GameElementFactory
{
    MAP_TYPE elementCollection;

    template <typename ITEM>
    bool addElement(vector3<int> pos);

    template <typename ITEM, GAME_ELEMENT_TYPE T>
    ITEM* getElement(vector3<int> pos);

public:
    GameElementFactory();

    bool addDoor(vector3<int> pos);
    bool addSwitch(vector3<int> pos);
    bool addSpikes(vector3<int> pos);
    bool addLadder(vector3<int> pos);
    bool addEnemy(vector3<int> pos);

    bool removeElement(vector3<int> pos);

    GameElement* getGeneric(vector3<int> pos);
    ElementDoor* getDoor(vector3<int> pos);
    ElementSwitch* getSwitch(vector3<int> pos);
    ElementSpikes* getSpikes(vector3<int> pos);
    ElementLadder* getLadder(vector3<int> pos);
    ElementEnemy* getEnemy(vector3<int> pos);

    MAP_TYPE& getCollection(){return elementCollection;}
    GameElement* searchNearest(vector3<int> pos);

};

#endif // GAMEELEMENTFACTORY_H
